package com.atguigui.leetcode;

/**
 * 754.到达终点数字
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/11/4 9:41
 */
public class P754ReachANumber {
    public static void main(String[] args) {
        Solution solution = new P754ReachANumber().new Solution();
        // TO TEST
    }


    class Solution {
        public int reachNumber(int target) {
            target = Math.abs(target);
            int k = 0;
            while (target > 0) {
                k++;
                target -= k;
            }
            //
            return target % 2 == 0 ? k : k + 1 + k % 2;
        }
    }
}
